package com.crk.shixiguanli.controller;

import com.crk.shixiguanli.entity.PayRecord;
import com.crk.shixiguanli.entity.Student;
import com.crk.shixiguanli.entity.StudentDto;
import com.crk.shixiguanli.service.StudentService;
import com.crk.shixiguanli.util.LayUiTableJson;
import com.crk.shixiguanli.util.Page;
import com.crk.shixiguanli.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Description:
 *
 * @author:
 * Date: 2020-04-02
 * Time: 15:49
 */
@RestController
@RequestMapping("student")
public class StudentController {

    @Autowired
    StudentService studentService;

    @RequestMapping("manage")
    public ModelAndView manage(){
        ModelAndView modelAndView = new ModelAndView("/workspace/student/studentList.html");
        return modelAndView;
    }

    @GetMapping("detail")
    public ModelAndView detail(){
        ModelAndView modelAndView = new ModelAndView("/workspace/student/studentAdd.html");
        return modelAndView;
    }

    @GetMapping("autoBaodao")
    public ModelAndView autoBaodao(){
        ModelAndView modelAndView = new ModelAndView("/workspace/student/autoBaodao.html");
        return modelAndView;
    }

    @PostMapping("/upload")
    public ResponseResult upload(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return ResponseResult.fail();
        }
        return studentService.upload(file);
    }

    @RequestMapping("queryStudentPage")
    public LayUiTableJson queryStudentPage(String studentName,String college,String professional,
                                            @RequestParam(defaultValue = "1") int page
            , @RequestParam(defaultValue = "10") int limit){
        Page pageInfo = new Page();
        pageInfo.setCurrentPage(page);
        pageInfo.setSize(limit);
        ResponseResult ResponseResult = studentService.queryStudentPage(studentName,college,professional
                ,pageInfo);
        LayUiTableJson layUiTableJson = new LayUiTableJson(0,null,pageInfo.getAllRow(),(List)ResponseResult.getData());
        return layUiTableJson;
    }

    @RequestMapping("getStaticByAge")
    public ResponseResult getStaticByAge(){
        return studentService.getStaticByAge();
    }

    @RequestMapping("getStaticByProvince")
    public ResponseResult getStaticByProvince(){
        return studentService.getStaticByProvince();
    }

    @RequestMapping("getStaticByGender")
    public ResponseResult getStaticByGender(){
        return studentService.getStaticByGender();
    }

    @RequestMapping("getStaticByNation")
    public ResponseResult getStaticByNation(){
        return studentService.getStaticByNation();
    }


    @RequestMapping("saveStudentBaseInfo")
    public ResponseResult saveStudentBaseInfo(StudentDto studentDto){
        return studentService.saveStudentBaseInfo(studentDto);
    }


    @RequestMapping("saveStudent")
    public ResponseResult saveStudent(Student student){
        return studentService.saveStudent(student);
    }






    @RequestMapping("confirmStudentInfo")
    public ResponseResult confirmStudentInfo(){
        return studentService.confirmStudentInfo();
    }


    @RequestMapping("getStudent")
    public ResponseResult getStudent(int id){
        return studentService.getStudent(id);
    }

    @RequestMapping("deleteStudent")
    public ResponseResult deleteStudent(int id){
        return studentService.deleteStudent(id);
    }

}
